using System;
using System.Collections;
using System.Data;
using NHibernate.Criterion;
using PetShop.Domain.Model;
using PetShop.Infrastructure.NHibernate;
using NHibernate;



namespace PetShop.Infrastructure.Gateways
{

		
	
	public class AccountGateway  {

		
		private readonly ISession _session;


		public AccountGateway()
		{ 
			_session = NHibernateHttpModule.CurrentSession; 
		}
		
		public Account GetAccount(string userId, string password) {

			Account acc = null;

			ICriteria crit = _session.CreateCriteria(typeof(Account));

			crit.Add(Restrictions.Eq("UserId", userId));
			crit.Add(Restrictions.Eq("Password", password));

			IList list = crit.List();

			if (list == null || list.Count < 1)
			{
				return null;
			}
			else
			{
				acc= (Account)list[0];
			}

			return acc;
		}

		
	
		public void Insert(Account acc)
		{
		   _session.Save(acc);
		}

		
		public void Update(Account myAccount) 
		{
		   _session.Update(myAccount);
		}


		
		
	}
}
